<template>
  <div>
    <order-info v-for="od in orders" :key="od.no" :od="od"></order-info>
  </div>
</template>

<script>
import OrderInfo from "@/components/OrderInfo";
import http from "@/utils/request";

export default {
  components: { OrderInfo },
  mounted() {
    let accessToken = this.$cookies.get("access_token");
    let ts = accessToken.split("."); // 根据 . 拆分jwt字符串
    let payload = JSON.parse(
      decodeURIComponent(
        escape(window.atob(ts[1].replace(/-/g, "+").replace(/_/g, "/")))
      )
    );
    let sub = payload.sub; // 获取到用户名
    http
      .post("/shopping/user", {
        userName: sub,
      })
      .then((res) => {
        this.userId = res.data.data.userId;
        http
          .post(`/orders`, {
            id: this.userId,
            status: this.status,
          })
          .then((res) => {
            this.orders = res.data.data;
            window.console.log(this.orders);
          });
      });
  },
  data() {
    return {
      userId: "",
      status: "5",
      orders: {},
    };
  },
};
</script>

<style></style>
